var testdata;
function queryTemplate(pageNum) {
	var name = $("#template_name").val();
	var description = $("#template_description").val();
	var groupid =  $("#groupid").val();
	$.cookie('query_name', name);
	$.cookie('query_des', description);
	$.cookie('groupid', groupid);
	$.ajax({
				type : "POST",
				contentType : "application/x-www-form-urlencoded; charset=utf-8",
				url : 'aadl/template/query',
				dataType : "json",
				data : {
					'pageNum' : pageNum,
					'query_name' : name,
					'query_des' : description,
					'groupid' : groupid
				},
				success : function(data) {
					testdata = data;
					if (data.success == "true") {
						var currentNum = data.currentNum;
						var totalNum = data.totalNum;
						$("#search_reuslt").hide();
						$("#template_list").show();
						$("#template_list tbody").html("");
						var rows = $("<tbody></tbody>");
						$
								.each(
										data.data,
										function(n, value) {
											var tr = $("<tr></tr>");
											var selectTd = $(
													"<td id='td_uri'></td>")
													.append(n + 1);
											var nameTd = $("<td></td>").append(
													value.name);
											var desTd = $("<td></td>").append(
													value.description);
											var operationTd;
												operationTd = $("<td></td>")
												.append(
														"<div class='btn-group'><button class=\"btn\" onclick=\"window.location.href='"+value.uri+"';\"><i class=\"icon-search\"></i>&nbsp;查看</button><button class=\"btn\" onclick=\"window.location.href='"+value.uri+"/inherit';\"><i class=\"icon-edit\"></i>&nbsp;使用</button></div>");
											tr.append(selectTd).append(nameTd)
													.append(desTd).append(
															operationTd)
													.appendTo(rows);
										});
						
						$("#template_list tbody").html(rows.html());
						$("#template_list tfoot").html("");
						var footTr = $("<tr></tr>");
						var footTd = $("<td></td>");
						footTd.attr("colspan","4");
						var div =  $("<div class=\"pagination pagination-centered\"></div>");
						var ul = $("<ul></ul>");
						if(currentNum == 1){
							ul.append("<li class=\"disabled\"><a href=\"javascript:void(0);\">&laquo;</a></li>");
						}else{
							var temp = currentNum -1;
							ul.append("<li><a href=\"javascript:void(0);\" onclick='queryTemplate("+temp+")'>&laquo;</a></li>");
						}
						
						ul.append("<li class=\"active\"><a href=\"javascript:void(0);\">"+currentNum+"</a></li>");
						for(var i=1;i<5;i++){
							var temp = currentNum +i;
							if(temp > totalNum){
								ul.append("<li class=\"disabled\"><a href=\"javascript:void(0);\">"+temp+"</a></li>");
							}else{
								ul.append("<li><a href=\"javascript:void(0);\" onclick='queryTemplate("+temp+")'>"+temp+"</a></li>");
							}
						}
								
						if(currentNum +1 > totalNum){							
							ul.append("<li class=\"disabled\"><a href=\"javascript:void(0);\">&raquo;</a></li>");
						}else{
							var temp = currentNum +1;
							ul.append("<li><a href=\"javascript:void(0);\" onclick='queryTemplate("+temp+")'>&raquo;</a></li>");
						}
						div.append(ul).appendTo(footTd);
						footTd.appendTo(footTr);
						
						$("#template_list tfoot").html(footTr.html());
					} else {
						$("#search_reuslt").show();
						$("#search_reuslt").text("系统内未检索到相关的架构模板");
						$("#template_list").hide();
					}
				}
			});
}